package com.coderg.gmall.oauth2.rabbitMq;

import com.coderg.gmall.rabbitMq.constant.RabbitConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @Author CoderG
 * @Date 2025/6/15 18:35
 **/
@Configuration
public class RabbitEQ {

    @Bean
    public Exchange cartExchange() {
        return ExchangeBuilder.directExchange(RabbitConst.CART_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue cartQueue() {
        return QueueBuilder.durable(RabbitConst.CART_QUEUE).build();
    }

    @Bean
    public Binding cartBingQueue(@Qualifier("cartQueue") Queue queue,
                                 @Qualifier("cartExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(RabbitConst.CART_ROUTING_KEY).noargs();
    }

}
